package com.example.xd.javatest.okhttp_test;

import android.util.Log;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @auther XuDan on 2020/7/6.
 */
public class OkhttpTest {
    /**
     * okHttpClient
     * Request
     * Call
     */
    public static void test_get() {
        String url = "http://blog.csdn.net/itachi85";
        Request.Builder requestBuilder = new Request.Builder().url(url);
        requestBuilder.method("GET", null);
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = requestBuilder.build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.i("xd---", response.body().string());
                Log.i("xd---", response.message());
                Log.i("xd---", response.code() + "--");

            }
        });

    }
}
